define(['app','pagination','datetime','js/directive/listTree','js/filter/tree2Arr','exporting','autocomplete'], function(app) {
    'use strict';
    app.controller('Auditing', function($scope, $http, dataFactoryCRM , $q, $timeout) {
	    $scope.search_param = {user:'',status:-1};
	    $scope.editData = {user_id:0};
	    $scope.addData = {dimissionTime:'',state:'',reson:'',beizhu:''}
	    $scope.teacherList = [{}];
	    $scope.userRoleSector = {user_id:0};
	    // $scope.pagerdata = { pageAll:1, pageNow:1, pageSize:$scope.psize, k: 3922 };     
	            //分页
	    $scope.pagerdata = {pageAll: 1,pageNow: 1, pageSize:$scope.psize,k: 3};
	    $scope.user;
	    $('.menu .item').tab();
	$scope.showEmlModal = function(user_id){

		$scope.userId = user_id;
		console.log(user_id);

     dataFactoryCRM.getDataByAPI('document/getEditInfo?user_id='+user_id)
          .then(function(d){
            if(d&&d.rcode){
              $timeout(function() {
                $scope.editUser = d.data['user'];
                
                $scope.editEmpl = d.data['userExt'];
                $scope.familys = d.data['family'];
                $scope.edus = d.data['education'];
                $scope.trains = d.data['train'];
                $scope.works = d.data['workexp'];            
             });                  
              $('.ui.show').modal('show');

            }else{
              $scope.api_error('接口请求失败');
            }
          });
	}

	$scope.update = function(user_id,param){
		dataFactoryCRM.getDataByAPI('auditing/update?user_id='+user_id+'&param='+param)
        .then(function(d){
        	console.log(d);
                  $scope.userMsg = d.msg;
                if (d.rcode) {
                	if(d.parames == 1){
                		$scope.api_success("审核通过成功");
                	}else{
                		$scope.api_success("退回修改成功");
                	}
                    
                    $scope.getPageData();//重新加载列表
                    return true;
                }else{
                     $scope.api_error( "审核失败" );
                    return false;
                }
            });
	}
    
    //获取分页数据
	    $scope.getPageData = function(){
	        var sUrl = "auditing/index";
	        var _param =  $scope.search_param;
	        _param['psize'] = $scope.pagerdata.pageSize;
	        _param['p'] = $scope.pagerdata.pageNow;
	        sUrl += "?"+$.param( _param ) ;
	        dataFactoryCRM.getDataByAPI( sUrl ).then( function( _d ){
	        	console.log(_d);
	        	$scope.auditing = _d.data;
	            $scope.rcode = _d.rcode;
	            $scope.pagerdata.pageSize = _d.psize;
	            $scope.pagerdata.pageAll = _d.pall;
	            $scope.pagerdata.pageNow = _d.p;
	            $scope.$emit("NOTBUSY");
	        });
	    }
	    $scope.getPageData();
	    $scope.search = function(){
	        $scope.getPageData();
	    }
 $scope.api_error = function ( msg ) {
        $('.modal.modal2').remove();
        $('<div class="ui small modal modal2" style="text-align: center;"><div class="header">提示</div><div class="content"><i class="huge red warning outline icon"></i>' +
            '<p style="padding-top: 15px;">'+msg+'</p>' +'</div></div>'
        ).modal('show');
    };
     $scope.api_success = function( msg ){
        $('.modal.modal1').remove();
        $('<div class="ui small modal modal1" style="text-align: center;"><div class="header">提示</div><div class="content"><i class="huge green check circle outline icon"></i>' +
                '<p style="padding-top: 15px;">'+msg+'</p>' +'</div></div>'
            ).modal('show');
    };
	    //加载部门
	    $scope.busy = dataFactoryCRM.getDataByAPI('user/getPageParam')
	        .then( function( data ) {
	            $scope.busy = false;
	            if( data ) {
	                $scope.sectors = data.sector;
	                $scope.roles = data.role;
	                // console.log( $scope.sectors)
	            }
	        });



	});
});